package com.lengyu.vxminiprogram.common;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lengyu.vxminiprogram.security.rest.dto.JwtUser;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * Created By liuyu On 2019/12/06
 */
@Data
public class BaseEntity implements Serializable {

    @TableId(value = "id",type = IdType.ASSIGN_UUID)
    private String id;

    @DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT) // 新增执行
    private Date createTime;

    @DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行
    private Date updateTime;

    private String createId;

    private String updateId;

    public void initInsert(){
        JwtUser user =AuthUtil.getCurrentJwtUser();
        this.id=null;
        this.createId = user.getId();
        this.updateId = createId;
    }

    public void initUpdate(){
        JwtUser user =AuthUtil.getCurrentJwtUser();
        this.updateId = user.getId();
    }
}
